package com.admin.business.workManagement.venusOaWorkInstall;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 工作安排可以不受限制的岗位
 * @create: 2023-11-14 10:49:26
 **/
@Service("venusOaWorkInstallService")
@Slf4j
public class VenusOaWorkInstallService{

    @Resource
    VenusOaWorkInstallDao venusOaWorkInstallDao;

    /**
     * 添加工作安排可以不受限制的岗位,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司id
     *                   - pro_id:项目id
     *                   - dept_id:部门id
     *                   - post_id:处理岗位
     *                   - begin_time:创建时间
     *                   - begin_id:创建人
     *                   - state:状态 0 正常 1 删除
     * @return
     * @author wdf
     * @create: 2023-11-14 10:49:26
     */
    @OpenApi
    public Return addVenusOaWorkInstall(CDO cdoRequest) {
        venusOaWorkInstallDao.addVenusOaWorkInstall(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新工作安排可以不受限制的岗位数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:公司id
     *                   - pro_id:项目id
     *                   - dept_id:部门id
     *                   - post_id:处理岗位
     *                   - begin_time:创建时间
     *                   - begin_id:创建人
     *                   - state:状态 0 正常 1 删除
     * @return
     * @author wdf
     * @create: 2023-11-14 10:49:26
     */
    @OpenApi
    public Return updateVenusOaWorkInstallById(CDO cdoRequest) {
        venusOaWorkInstallDao.updateVenusOaWorkInstallById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除工作安排可以不受限制的岗位数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 10:49:26
     */
    @OpenApi
    public Return deleteVenusOaWorkInstallById(CDO cdoRequest){
        int count = venusOaWorkInstallDao.deleteVenusOaWorkInstallById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除工作安排可以不受限制的岗位数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-14 10:49:26
     */
    @OpenApi
    public Return deleteVenusOaWorkInstall(CDO cdoRequest) {
        int count = venusOaWorkInstallDao.deleteVenusOaWorkInstall(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取工作安排可以不受限制的岗位数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 10:49:26
     */
    @OpenApi
    public Return getVenusOaWorkInstallById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaWorkInstallDao.getVenusOaWorkInstallById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取工作安排可以不受限制的岗位数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-14 10:49:26
     */
    @OpenApi
    public Return getVenusOaWorkInstallListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaWorkInstallDao.getVenusOaWorkInstallListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaWorkInstallDao.getVenusOaWorkInstallCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取工作安排可以不受限制的岗位数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 10:49:26
     */
    @OpenApi
    public Return getVenusOaWorkInstallListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaWorkInstallDao.getVenusOaWorkInstallListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaWorkInstallDao.getVenusOaWorkInstallCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
